#include "BlockQueue.hpp"
#include <ctime>
#include <unistd.h>
void *Consumer(void *args)
{
    std::cout << "开始消费......." << std::endl;
    BlockQueue<int> *bq = static_cast<BlockQueue<int> *>(args);
    int x = 0;
    while (true)
    {
        bq->pop(&x);
        std::cout << "消费了一个数据：" << x << std::endl;
        sleep(1);
    }
}
void *Productor(void *args)
{
    std::cout << "开始生产......." << std::endl;
    BlockQueue<int> *bq = static_cast<BlockQueue<int> *>(args);
    while (true)
    {
        int x = rand() % 10;
        bq->push(x);
        std::cout << "生产了一个数据：" << x << std::endl;
    }
}
int main()
{
    srand(time(nullptr));
    BlockQueue<int> *bq = new BlockQueue<int>;
    pthread_t c, p;
    pthread_create(&c, nullptr, Consumer, bq);
    pthread_create(&p, nullptr, Productor, bq);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);
    return 0;
}